import {
  LOAD,
  LOAD_SUCCESS,
  LOAD_FAIL
} from './constants'



const initialState = {
  loaded: false,
  loading: false,
  pages: 0,
  page: 0,
  items: [],
};

export default function reducer(state = initialState, action = {}) {
  switch (action.type) {
    case LOAD:
      return {
        ...state,
        loading: true,
        loaded: false
      };
    case LOAD_SUCCESS:
      return {
        ...state,
        loading: false,
        loaded: true,
        items: action.result.items,
        pages: action.result.pages,
        page: action.result.page
      };
    case LOAD_FAIL:
      return {
        ...state,
        loading: false,
        loaded: false,
        error: action.error
      };
    default:
      return state;
  }
}